// transformer1-module
import * as ts from 'typescript';
import shell from "shelljs"
import path from "path"
export default function(program: ts.Program, pluginOptions: {}) {
    shell.rm('-rf', 'dist');
    return (ctx: ts.TransformationContext) => {
        return (sourceFile: ts.SourceFile) => {
            console.log(sourceFile.fileName)
            const newSourceFile = {...sourceFile}
            const cc = path.parse(sourceFile.fileName)
            if(cc.ext===".ts"){
                cc.ext=".mjs"
                cc.base=`${cc.name}.mjs`
            }
            console.log(cc)
            console.log(path.format(cc))
            newSourceFile.fileName = path.format(cc).normalize();
            console.log(newSourceFile.fileName)
            function visitor(node: ts.Node): ts.Node {
                return ts.visitEachChild(node, visitor, ctx);
            }
            return ts.visitEachChild(sourceFile, visitor, ctx);
        };
    };
}

